using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_Shop_UserExpRecorde : Member, IRequiresSessionState
{
	protected Literal LitUserExp;
	protected DropDownList DropType;
	protected TextBox begindate;
	protected TextBox EndDate;
	protected Button sb;
	protected GridView GridView1;
	private Pagination _pagehander;
	private string wherestr = "";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected Pagination m_pagehander
	{
		get
		{
			Pagination pagehander;
			if (this._pagehander == null)
			{
				this._pagehander = new Pagination();
				this._pagehander.P_Object = "记录";
				pagehander = this._pagehander;
			}
			else
			{
				pagehander = this._pagehander;
			}
			return pagehander;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.GridView1.PageIndexChanging += new GridViewPageEventHandler(this.GridView1_PageIndexChanging);
		string text = "0";
		if (!string.IsNullOrEmpty(this.GetUserExpRecorde()))
		{
			text = this.GetUserExpRecorde();
		}
		this.LitUserExp.Text = text;
		if (!base.IsPostBack)
		{
			this.BindList();
		}
		this.begindate.Attributes.Add("onClick", "SelectDate(" + this.begindate.UniqueID + ",'yyyy-MM-dd');");
		this.EndDate.Attributes.Add("onClick", "SelectDate(" + this.EndDate.UniqueID + ",'yyyy-MM-dd');");
	}
	protected string GetUserExpRecorde()
	{
		DataSet dataSet = this.conn.GetDataSet("select sum(UserEP) as TotalCount from HL_UserExpRecorde where UserID=" + int.Parse(Fetch.GetCookies("Howave_UserID")));
		return dataSet.Tables[0].Rows[0]["TotalCount"].ToString();
	}
	private void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.GridView1.PageIndex = e.NewPageIndex;
		this.BindList();
	}
	protected void BindList()
	{
		if (this.wherestr != string.Empty)
		{
			this.GridView1.DataSource = this.conn.GetDataTable("Select * From [HL_UserExpRecorde] " + this.wherestr + " ORDER BY ID DESC");
			this.GridView1.DataBind();
		}
		else
		{
			this.GridView1.DataSource = this.conn.GetDataTable("Select * From [HL_UserExpRecorde] Where UserID=" + base.user.UserID + " ORDER BY ID DESC");
			this.GridView1.DataBind();
		}
	}
	protected void QuestString()
	{
		this.wherestr = "and UserID=" + base.user.UserID + " ";
		string selectedValue = this.DropType.SelectedValue;
		if (selectedValue != "")
		{
			this.wherestr += string.Format("and cType={0} ", selectedValue);
		}
		string text = this.begindate.Text;
		if (text != string.Empty)
		{
			try
			{
				Convert.ToDateTime(text);
			}
			catch
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
			}
			this.wherestr = this.wherestr + "and datediff(dd,CreateTime,'" + text + "')<=0 ";
		}
		string text2 = this.EndDate.Text;
		if (text2 != string.Empty)
		{
			try
			{
				Convert.ToDateTime(text2);
			}
			catch
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
			}
			if (!string.IsNullOrEmpty(text) && Convert.ToDateTime(text2) < Convert.ToDateTime(text))
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
			}
			this.wherestr = this.wherestr + "and datediff(dd,CreateTime,'" + text2 + "')>=0 ";
		}
		if (this.wherestr != string.Empty)
		{
			this.wherestr = "and" + this.wherestr;
			this.wherestr = this.wherestr.Replace("andand", "where");
		}
	}
	protected void DropType_Onchange(object sender, EventArgs e)
	{
		this.QuestString();
		this.BindList();
	}
	protected void Search_OnClick(object sender, EventArgs e)
	{
		this.QuestString();
		this.BindList();
	}
	protected string GetcType(object obj)
	{
		string text = obj.IsNull(new object[0]);
		string text2 = text;
		string result;
		if (text2 != null)
		{
			if (text2 == "0")
			{
				result = "消耗";
				return result;
			}
			if (text2 == "1")
			{
				result = "获得";
				return result;
			}
			if (text2 == "2")
			{
				result = "推广";
				return result;
			}
			if (text2 == "3")
			{
				result = "抽奖花费";
				return result;
			}
			if (text2 == "5")
			{
				result = "货币兑换";
				return result;
			}
		}
		result = "后台处理";
		return result;
	}
}
